import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

export interface People{
  name:string;
  age:number;
  id:number;
}
export interface Animal{
  name:string;
  weight:number;
}

@Injectable()
export class PeopleService {

  constructor(private http:HttpClient){ }

  fetchPeople():Observable<People[]>{
    const header = {
      'token':'222222222'
    }
    return this.http.get<People[]>('/assets/v2/data/people.json',{
      headers:header,
      params:{id:'1111'},
    });
  }

  fetchAnimal():Observable<Animal[]>{
    const newAnimal = {
      name:'狮子',
      weight:300
    }
    return this.http.post<Animal[]>('/assets/data/animal.json',newAnimal,{headers:{'token':'222222'}});
  }
}
